import groupService from "../service/group";
import { codeFail, codeSuccess } from "./resultData";

export default function (app: any) {
    app.get("/apple/group", async (req, res) => {
        const data = await groupService.queryList();
        res.send(codeSuccess(data));
    });
    app.post("/apple/group", async (req, res) => {
        const data = await groupService.insert(req.body);
        if (!data) {
            return res.send(codeFail("新增失败"));
        }
        res.send(codeSuccess(data));
    });
    app.delete("/apple/group", async (req, res) => {
        const data = await groupService.deleteById(req.query.id);
        if (!data) {
            return res.send(codeFail("删除失败"));
        }
        res.send(codeSuccess());
    });

    app.put("/apple/group", async (req, res) => {
        const data = await groupService.update(req.body);
        if (!data) {
            return res.send(codeFail("更新失败"));
        }
        res.send(codeSuccess());
    });
}
